home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / test / egchi.c next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  5.6 KB  |  166 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.4 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/egchi.c,v 1.4 1992/10/23 19:09:28 koziol beta koziol $
  30.  
  31. $Log: egchi.c,v $
  32.  * Revision 1.4  1992/10/23  19:09:28  koziol
  33.  * Updated for new Vset calls, DFvsetopen(), DFvsetclose, and changed
  34.  * VFREESPACE and VGETSPACE to HDfreespace() and HDgetspace()
  35.  *
  36.  * Revision 1.3  1992/05/29  19:13:01  mfolk
  37.  * Added int32 casts to make a couple of routines work with Convex.
  38.  *
  39.  * Revision 1.2  1992/05/18  22:11:07  sxu
  40.  * modified constants for number types
  41.  *
  42.  * Revision 1.1  1992/03/01  22:29:07  dilg
  43.  * Initial revision
  44.  *
  45.  * Revision 1.1  1992/02/29  20:19:13  likkai
  46.  * Initial revision
  47.  *
  48. */
  49. /*
  50.     ===============================
  51.     SAMPLE VSET PROGRAM
  52.     Jason Ng NCSA FEB-28-91
  53.     ===============================
  54.  
  55.     This program demonstrates the use of the high-level VSET write routines.
  56.     It shows how data can be stored in vdatas, and how vgroups can be created
  57.     from vdatas, vgroups and other HDF elements.
  58.  
  59.     This example creates a file "egchi.hdf" that may be viewed using the
  60.     vset utility "vshow".
  61.  
  62.     DETAILS
  63.  
  64.     This example shows how pressure data  and color data can be stored as a 
  65.     vset.  To store pressure data, a field named "PRES", is defined of 
  66.     float type. The routine VHstoredata() stores the pressure values in a vdata.
  67.  
  68.     Color data comprises 3 components (red, green, blue). These can be stored as
  69.     3 different fields in 3 vdatas. But this example shows that they can be
  70.     treated as ONE field, and stored together as a compound field called "COLOR".
  71.     The number of components of a field is called its order.  In this case, 
  72.     "COLOR" has order=3. (whereas "PRES" above has order=1).
  73.  
  74.     Note that VHstoredatam() must be used to store values of a compound field.
  75.     This is similar to VHstoredata() but has an extra argument for spefcifying
  76.     the order.
  77.  
  78.     Finally a vgroup is created, and the ids of the created vdatas are stored
  79.     in the vgroup. This effectively links the vdatas together. This example
  80.     also shows that you can insert another vgroup, as well as a non-vset element
  81.     (in this case, some element with tag=7777 and ref=1) into a vgroup.
  82. */
  83.  
  84. #include "vg.h"
  85.  
  86. #define FS  "egchi.hdf"
  87. #define NP 100
  88. #define NC 60
  89. #define ORDERC 3 /* 3 color components: rgb */
  90.  
  91. main (ac,av)   int ac; 
  92. char**av; 
  93. {
  94.     int n = ac;
  95.  
  96.     printf("%s: demonstrates and tests high-level VSET routines\n", av[0]);
  97.     printf("It also shows how you can link other HDF elements\n");
  98.     printf("(eg rasters, palettes) into vgroups\n");
  99.     printf("\n");
  100.     printf("It creates 2 vdatas, a vgroup, and a non-vset element\n");
  101.     printf("then link them all into one vgroup\n");
  102.  
  103.     printf("Vdata 1 contains an order-1 float field PRES\n");
  104.     printf("Vdata 2 contains an order-3 integer field COLOR\n\n");
  105.     printf("The non-vset element has tag=7777, ref=1\n");
  106.  
  107.     doit();
  108.  
  109.     printf("\nsuccess: created file %s\n", FS);
  110.     printf(" Uset the utility vshow to view this file: \n");
  111.     printf("\t\t vshow %s +\n", FS);
  112.     printf("\t\t\t or\n");
  113.     printf("\t\t vshow %s \n", FS);
  114.     printf("results should be as in %s.result\n",av[0]);
  115. }
  116.  
  117. /* ------------------------------------------------------------------ */
  118.  
  119. doit() {
  120.     HFILEID f;
  121.     float pvals[NP];
  122.     int cvals[NC][ORDERC];
  123.     int i,j;
  124.  
  125.     int pid, cid;         /* refs of vdatas */
  126.     int eid;             /* empty vgroup's ref  */
  127.     int gid;             /* vgroup's ref  */
  128.     int32 tags[10], refs[10];
  129.     char * CLASS = "EXAMPLE";
  130.  
  131.     /* --- generate data here --- */
  132.     for(i=0;i<NP;i++)  pvals[i] = 100.0  + i * 0.001;
  133.     for(i=0;i<NC;i++) for(j=0;j<3;j++)  cvals[i][j] =   i + j*100;
  134.  
  135.     /* ---- open a new file --- */
  136.     if (FAIL==(f=DFvsetopen(FS ,DFACC_ALL,0))) 
  137.     { printf("open %s err\n",FS); exit(0); }
  138.  
  139.     /* ---- create 2 vdatas --- */
  140.     pid = VHstoredata (f, "PRES", (unsigned char*) pvals ,NP, DFNT_FLOAT32, "pressure vals",CLASS);
  141.     if (pid  == -1) { printf(" VHstoredata store PRES err. "); }
  142.  
  143.     cid  = VHstoredatam(f, "COLOR",(unsigned char*) cvals, NC, DFNT_INT32, "rgb colors", CLASS, 3);
  144.     if (cid  == -1) { printf(" VHstoredata store COLOR err. "); }
  145.  
  146.     eid  = VHmakegroup (f, tags, refs, (int32) 0, 
  147.                                        "This is an EMPTY vgroup", CLASS);
  148.     if (eid  == -1) { printf(" VHmakegroup err\n"); }
  149.  
  150.     /* --- create a new vgroup to store the 2 vdatas , the empty vgroup 
  151.     and the non-vset element -- */
  152.  
  153.         tags[0] = VSDESCTAG;  refs[0] = pid;
  154.         tags[1] = VSDESCTAG;  refs[1] = cid;
  155.         tags[2] = VGDESCTAG;  refs[2] = eid;
  156.         tags[3] = 7777 ;      refs[3] = 1;
  157.  
  158.     gid  = VHmakegroup (f, tags, refs, (int32) 4, 
  159.                                      "here is a vset with 4 links", CLASS);
  160.  
  161.     if (eid  == -1) { printf(" VHmakegroup err\n"); }
  162.  
  163.     /* --- close the file --- */
  164.     DFvsetclose(f);
  165. }
  166.